/*
 * This file is part of "Deathwatch Ammo Counter for Android".
 *
 * "Deathwatch Ammo Counter for Android" is free software: you can redistribute
 * it and/or modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation, either version 3 of the License, 
 * or (at your option) any later version.
 *
 * "Deathwatch Ammo Counter for Android" is distributed in the hope that it 
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with "Deathwatch Ammo Counter for Android".  
 * If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package com.TikiiTorch.Deathwatch.AmmoCounter;

public class AmmoLoad {

	private Ammunition ammunition;

	private AmmoClip ammoClip;

	private int initialAmount;

	private int bagAmount;

	/**
	 * Creates an instance of an AmmoSupply. This represents a single supply of
	 * a single type of ammunition.
	 * 
	 * @param ammunition
	 *            The ammunition for this supply
	 * @param initialAmount
	 *            The starting amount of this Ammunition
	 * @param clipSize
	 *            The size of the clip
	 */
	public AmmoLoad(Ammunition ammunition, int initialAmount, int clipSize) {
		this.ammunition = ammunition;
		this.initialAmount = this.bagAmount = initialAmount;
		ammoClip = new AmmoClip(clipSize);
	}
	
	public AmmoLoad(Ammunition ammunition, int inClip, int inBag, int clipSize){
		this.ammunition = ammunition;
		ammoClip = new AmmoClip(clipSize);
		this.bagAmount = inBag;
		ammoClip.setRoundCount(inClip);
	}

	/**
	 * Gets the name of this Ammunition
	 * 
	 * @return The name of this Ammunition
	 */
	public String getName() {
		return this.ammunition.getName();
	}

	/**
	 * Gets the effect of this ammunition
	 * 
	 * @return The effect that this Ammunition gives
	 */
	public String getEffect() {
		return this.ammunition.getEffect();
	}

	public int getClipSize() {
		return this.ammoClip.getClipSize();
	}

	public int getClipAmount() {
		return this.ammoClip.getRoundCount();
	}
	
	public int getBagAmount() {
		return this.bagAmount;
	}

	/**
	 * Gets the initial amount of Ammunition in this supply
	 * 
	 * @return The initial amount of ammunition
	 */
	public int getInitialAmount() {
		return this.initialAmount;
	}

	/**
	 * Gets the current amount of ammunition in this supply
	 * 
	 * @return The number of rounds that are currently in this supply
	 */
	public int getCurrentAmount() {
		return this.bagAmount + this.ammoClip.getRoundCount();
	}

	public int getClipNum() {
		return (this.bagAmount + this.ammoClip.getRoundCount())
				/ this.ammoClip.getClipSize();
	}

	/**
	 * Removes rounds from this supply of ammunition
	 * 
	 * @param count
	 */
	public void expendRounds(int count) {
		this.ammoClip.expendRounds(count);
	}

	/**
	 * Reloads the clip for this Supply
	 */
	public void reloadClip() {
		int roundsUsed = 0;

		if (this.bagAmount <= ammoClip.getClipSize()) {
			roundsUsed = this.ammoClip.reload(this.bagAmount);
		} else {
			roundsUsed = this.ammoClip.reload();
		}

		this.bagAmount -= roundsUsed;
	}

	

}
